<template>
    <div class="header">
        <van-icon name="arrow-left" class="icon" @click="goBack" />
        <div>{{ porps.title }}</div>
        <div class="edit" v-if="edit" @click="editClick">{{ store.state.Cart.edit ? '编辑' : '完成' }}</div>
    </div>
</template>

<script setup>
let porps = defineProps(['title', 'edit'])

// 引入userRouter
import { useRouter } from 'vue-router';
let router = useRouter();
const goBack = () => {
    router.go(-1);
}
// 使用全局事件总线
import emitter from '../common/js/evenbus';
import { useStore } from 'vuex';
let store = useStore();
import { Toast } from 'vant'
const editClick = () => {
    // 先判断购物车cartList中 是否有数据 有数据才能编辑 没有无法编辑
    if (store.state.Cart.cartList.length) {
        emitter.emit('edit');
        store.commit('Edit')
    } else {
        Toast({
            message: '购物车空空如也',
            icon: 'fail'
        })
    }
}
</script>

<style scoped lang="less">
.header {
    background-color: #fff;
    height: 50px;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-bottom: 1px solid #d7d7d7;

    /* position: relative; */
    .icon {
        position: absolute;
        left: 10px;
    }

    .edit {
        position: absolute;
        right: 10px;
        font-size: 14px;
    }
}
</style>
